package cn.chrilwe.pigpig.im.service.executor;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import cn.chrilwe.pigpig.im.Main;

public class TaskExecutor {
	
	private static volatile TaskExecutor executor;
	
	private static ThreadPoolExecutor pool = null;

	private TaskExecutor() {
		ArrayBlockingQueue workQueue = new ArrayBlockingQueue(20);
		pool = new ThreadPoolExecutor(10, 16, 10, TimeUnit.SECONDS, workQueue);
	}
	
	public static TaskExecutor getInstance() {
		if(executor == null) {
			synchronized (Main.class) {
				if(executor == null) {
					return new TaskExecutor();
				}
			}
		}
		return executor;
	}

	public void executor(Runnable runnable) {
		pool.execute(runnable);
	}
	
}
